﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web.Mvc;
using OpenFlashChart;
using Peak.ApplicationServices.Services;
using Peak.Core;
using Peak.Core.DataInterfaces;
using MvcContrib;
using Peak.Web.Controllers.Models;
using Peak.Web.Controllers.Services;
using SharpArch.Core.PersistenceSupport;
using SharpArch.Web.NHibernate;

namespace Peak.Web.Controllers
{
  public class SprintsController : BaseController
  {    
    private readonly ISprintService _sprintService;

    public SprintsController(ISessionService sessionService, ISprintService sprintService)
      : base(sessionService)
    {
      _sprintService = sprintService;
    }

    public ActionResult Index()
    {
      _sessionService.BackLink.Reset();
      Project p = _sessionService.Project;
      return View(new SprintsModel(_sessionService.Project.Sprints.Select(f=> new SprintModel(f)).ToList()));
    }   
 
    [Transaction]
    public ActionResult Remove(int sprintId)
    {      
      Sprint s =_sprintService.Get(sprintId);
      _sessionService.Project.RemoveSprint(s);
      _sprintService.Delete(s);
      return this.RedirectToAction(f => f.Index());
    }    
  }
}
